package worker;

import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import javax.jms.JMSException;

import server.Content;

import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.AmazonSQSClient;
import com.amazonaws.services.sqs.model.DeleteMessageRequest;
import com.amazonaws.services.sqs.model.Message;
import com.amazonaws.services.sqs.model.ReceiveMessageRequest;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;

import data.Data;

public class GetContent extends TimerTask{
	public void run()
	{
		DBCollection coll = Data.data("urlCraw");
		DBObject object = coll.findAndModify(new BasicDBObject("active","1"), new BasicDBObject("$set", new BasicDBObject("active", "0")));
		
		if(object != null)
		{
			DBCollection collss = Data.data("loglinkworker");
			BasicDBObject dbObjects = new BasicDBObject();
			dbObjects.put("link", "1");
			collss.insert(dbObjects);
			
			try {
				new Content(object);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	public static void main(String[] args) throws JMSException, IOException {

		Timer timer = new Timer();
		GetContent setDataWorker = new GetContent();

	    // Schedule to run after every 3 second(3000 millisecond)

	    timer.scheduleAtFixedRate( setDataWorker, 0,10);
	}
}
